package com.example.schoolnewsapp;

import androidx.fragment.app.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.schoolnewsapp.activity.LoginOrRegisterActivity;
import com.example.schoolnewsapp.database.DBHelper;
import com.example.schoolnewsapp.util.SharedPreUtil;

import de.hdodenhof.circleimageview.CircleImageView;

public class MineFragment extends Fragment implements View.OnClickListener {
    private View view;
    private CircleImageView circleImageView;
    private TextView my_head_name , my_exit ,my_account,my_comment;
    private DBHelper dbHelper;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_mine, container, false);

        circleImageView = view.findViewById(R.id.my_head);
        my_head_name = view.findViewById(R.id.my_head_name);
        my_exit = view.findViewById(R.id.my_exit);
        my_account = view.findViewById(R.id.my_acc);
        my_comment = view.findViewById(R.id.my_comm);
        dbHelper = new DBHelper(getContext(), "UserDB.db", null, 6);
        String username = (String) SharedPreUtil.getParam(getContext(), SharedPreUtil.LOGIN_DATA, "");
        my_head_name.setText(username);

        circleImageView.setOnClickListener(this);
        my_head_name.setOnClickListener(this);
        my_exit.setOnClickListener(this);
        my_account.setOnClickListener(this);
        my_comment.setOnClickListener(this);
        return view;
    }



    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.my_head: {
                Intent intent = new Intent(getContext(), PersonDataActivity.class);
                startActivity(intent);
            }
            break;

            case R.id.my_exit: {
                //重新跳转到登录页面
                Intent intent = new Intent(getContext(), LoginOrRegisterActivity.class);
                startActivity(intent);
                getActivity().finish();
            }
            break;
            case R.id.my_comm: {
                Intent intent = new Intent(getContext(),CommentActivity.class);
                startActivity(intent);
            }
            break;

            case R.id.my_acc: {
                Intent intent = new Intent(getContext(), EditMineActivity.class);
                startActivity(intent);
            }
            break;
            default:
                break;
        }
    }
}